When a same subject is captured by two cameras arranged horizontally, a difference occurs in a horizontal direction between positions of the subject in captured two images because of a difference between positions of the cameras. The difference between the positions of the subject in both images is called “disparity”. A distance from the cameras to the subject is proportional to an inverse of the disparity. That is, the disparity decreases as a subject is farther and increases as the subject is nearer.
In stereo matching, a small area (block) is cut out from each of images captured by two cameras, and the disparity is determined by searching for a position where a degree of similarity between both small areas is highest, between the images. More specifically, when an image captured by one camera (for example, a left image captured by a camera arranged on a left side) is caused to be a reference, a range within which a similarity degree is searched in an image captured by the other camera (for example, a right image captured by a camera arranged on a right side) is from same coordinates as coordinates of a base block in the left image to coordinates away from the coordinates in a horizontal direction by a maximum disparity (for example, 128 pixels).
Actually, however, it is difficult to arrange two cameras completely horizontally, and a difference in a vertical direction or a rotation direction occurs. When such a difference occurs, matching may not be obtained, or a block different from the base block may match wrongly even if a block located on a line with a vertical-direction coordinate equal to a vertical-direction coordinate of the base block is searched for by changing a horizontal-direction position.
If such a difference is a static difference between cameras due to setting conditions or individual differences of lenses, it is possible to rectify the difference by an inspection performed at a manufacturing stage or at time of shipment. However, as for a dynamic difference between cameras due to vibration or the like by moving objects such as automobiles, the difference cannot be rectified by the inspection performed at time of shipment or the like.
Therefore, a method is conceivable in which a similarity degree search range is spread also in the vertical direction on an assumption that there is a vertical-direction difference to some extent. However, there are problems that the number of functional units required for similarity degree calculation increases and that a processing time period is lengthened.